<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <button id='copy'> Copy </button>
</body>
<script>
    window.onload = function(){
        var copy = document.getElementById('copy');
        copy.onclick = function(){
            copyToClip('复制的内容','复制后的提示');
        }
    }
    /**
    * 复制内容到粘贴板
    * content : 需要复制的内容
    * message : 复制完后的提示，不传则默认提示"复制成功"
    */
    function copyToClip(content, message) {
        var aux = document.createElement("input"); 
        aux.setAttribute("value", content); 
        document.body.appendChild(aux); 
        aux.select();
        document.execCommand("copy"); 
        document.body.removeChild(aux);
        if (message == null) {
            alert("复制成功");
        } else{
            alert(message);
        }
    }
</script>
</html>